<template>
  <page-header-wrapper>
    <a-space direction="vertical" style="width: 100%">
      <a-row :gutter="24">            
        <a-col :span="12">
          <a-card :loading="loading" title="内存" :bordered="false">
            <a-descriptions :column="2">
              <a-descriptions-item label="最大内存">
                {{ server.mem.max }} GB
              </a-descriptions-item>
              <a-descriptions-item label="空闲内存">
                {{ server.mem.free }} GB
              </a-descriptions-item>
              <a-descriptions-item label="PID">
                {{ server.pid }}
              </a-descriptions-item>
            </a-descriptions>
          </a-card>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="24">
          <a-card :loading="loading" title="服务器信息" :bordered="false">
            <a-descriptions :column="2" v-if="server.host">
              <a-descriptions-item label="服务器名称">
                {{ server.host.name }}
              </a-descriptions-item>
              <a-descriptions-item label="操作系统">
                {{ server.os.name + ' v' + server.os.version }}
              </a-descriptions-item>
              <a-descriptions-item label="服务器IP">
                {{ server.host.address }}
              </a-descriptions-item>
              <a-descriptions-item label="系统架构">
                {{ server.os.arch }}
              </a-descriptions-item>
            </a-descriptions>
          </a-card>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="24">
          <a-card :loading="loading" title="Java虚拟机信息" :bordered="false">
            <a-descriptions :column="2" v-if="server.jvm">
              <a-descriptions-item label="Java名称">
                {{ server.jvm.name }}
              </a-descriptions-item>
              <a-descriptions-item label="Java版本">
                {{ server.jvm.version }}
              </a-descriptions-item>
              <a-descriptions-item label="启动时间">
                {{ server.jvm.startTime }}
              </a-descriptions-item>
              <a-descriptions-item label="运行时长">
                {{ server.jvm.runTime }}
              </a-descriptions-item>
              <a-descriptions-item label="安装路径">
                {{ server.jvm.homeDir }}
              </a-descriptions-item>
              <a-descriptions-item label="项目路径">
                {{ server.jvm.userDir }}
              </a-descriptions-item>
              <a-descriptions-item label="运行参数">
                {{ server.jvm.inputArgs }}
              </a-descriptions-item>
              <a-descriptions-item label="运行参数">
                {{ server.jvm.inputArgs }}
              </a-descriptions-item>
            </a-descriptions>
          </a-card>
        </a-col>
      </a-row>
    </a-space>
  </page-header-wrapper>
</template>

<script>

import { getServer } from '@/api/monitor/server'
import { tableMixin } from '@/store/table-mixin'

export default {
  name: 'Server',
  mixins: [tableMixin],
  data () {
    return {
      server: [],
      loading: true,
      memColumns: [
        {
          title: '属性',
          dataIndex: 'name'
        },
        {
          title: '内存',
          dataIndex: 'mem',
          scopedSlots: { customRender: 'mem' }
        },
        {
          title: 'JVM',
          dataIndex: 'jvm',
          scopedSlots: { customRender: 'jvm' }
        }
      ],
      memData: [],
      sysColumns: [
        {
          title: '盘符路径',
          dataIndex: 'dirName',
          ellipsis: true
        },
        {
          title: '文件系统',
          dataIndex: 'sysTypeName'
        },
        {
          title: '盘符类型',
          dataIndex: 'typeName',
          ellipsis: true
        },
        {
          title: '总大小',
          dataIndex: 'total',
          scopedSlots: { customRender: 'total' }
        },
        {
          title: '可用大小',
          dataIndex: 'free',
          scopedSlots: { customRender: 'free' }
        },
        {
          title: '已用大小',
          dataIndex: 'used',
          scopedSlots: { customRender: 'used' }
        },
        {
          title: '已用百分比',
          dataIndex: 'usage',
          scopedSlots: { customRender: 'usage' }
        }
      ],
      sysData: []
    }
  },
  filters: {
  },
  created () {
    this.getList()
  },

  watch: {
  },
  methods: {
    /** 查询服务信息 */
    getList () {
      // this.loading = true
      getServer().then(response => {
          const serverData = response
          this.server = serverData
          // this.memData = [
          //   {
          //     name: '总内存',
          //     mem: serverData.mem.max,
          //     jvm: serverData.jvm.total
          //   },
          //   {
          //     name: '已用内存',
          //     mem: serverData.mem.used,
          //     jvm: serverData.jvm.used
          //   },
          //   {
          //     name: '剩余内存',
          //     mem: serverData.mem.free,
          //     jvm: serverData.jvm.free
          //   },
          //   {
          //     name: '使用率',
          //     mem: serverData.mem.usage,
          //     jvm: serverData.jvm.usage
          //   }
          // ]
          // this.sysData = serverData.sysFiles
          setTimeout(() => {
            this.loading = false
          }, 500)
        }
      )
    }
  }
}
</script>
